<template>
  <div class="register_container">
    <router-view></router-view>
    <div class="register_box">
      <!-- 头像区域 -->
      <div class="avatar_box">
        <img src="../assets/logo.png" alt="" />
      </div>
      <el-form
        ref="registerFormRef"
        :model="registerForm"
        :rules="registerFormRules"
        label-width="0px"
        class="register_form"
      >
        <!-- 用户名 -->
        <el-form-item prop="username">
          <el-input
            v-model="registerForm.username"
            placeholder="用户名"
          ></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input
            v-model="registerForm.password"
            placeholder="密码"
          ></el-input>
        </el-form-item>
        <!-- 邮箱 -->
        <el-form-item prop="email">
          <el-input v-model="registerForm.email" placeholder="邮箱"></el-input>
        </el-form-item>
        <!-- 电话号 -->
        <el-form-item prop="telephone">
          <el-input
            v-model="registerForm.telephone"
            placeholder="电话号"
          ></el-input>
        </el-form-item>

        <el-form-item label="label" class="btns">
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button type="info" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  registerUsername,
  registerPassword,
  registerEmail,
  registerTelephone,
} from "../vaildate";
export default {
  name: "Register",
  data() {
    return {
      registerForm: {
        username: "",
        password: "",
        email: "",
        telephone: "",
      },
      registerFormRules: {
        username: [{ validator: registerUsername, trigger: "blur" }],
        password: [{ validator: registerPassword, trigger: "blur" }],
        email: [{ validator: registerEmail, trigger: "blur" }],
        telephone: [{ validator: registerTelephone, trigger: "blur" }],
      },
    };
  },
  methods: {
    login() {
      this.$router.push("/login");
    },
    submitForm() {
      this.$refs.registerFormRef.validate(async (valid) => {
        if (valid) {
          this.$http.post("login", this.registerForm).then((res) => {
            res = JSON.stringify(res.config.data);
            console.log(res);
          });
          alert("submit");
        } else {
          console.log("error submit");
          return false;
        }
      });
    },
  },
};
</script>
<style scoped>
.register_container {
  background-color: #2b4b6b;
  height: 100%;
}
.register_box {
  width: 550px;
  height: 400px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.avatar_box {
  height: 130px;
  width: 130px;
  border: 1px solid #eee;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 0 10px #ddd;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
}
.avatar_box img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #eee;
}
.register_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  top: 75px;
}
.btns {
  display: flex;
  justify-content: flex-end;
}
</style>